package com.yang.studentsapp.model;

import com.android.volley.Request;
import com.google.gson.reflect.TypeToken;
import com.yang.studentsapp.CampusSociety;
import com.yang.studentsapp.ProtocolKey;
import com.yang.studentsapp.UrlConstant;
import com.yang.studentsapp.utils.MyRequest;
import com.yang.studentsapp.utils.RQManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ${Ян-Вэнь-Чао} on 2016/10/13.
 */
public class ModelSociety extends SettingModel {
    String mSocietyNewsAddress = UrlConstant.BaseUrl + UrlConstant.GetSocietyNewsList;
    public ModelSociety(IAction iAction) {
        super(iAction);
    }
    public void getSocietyNews(final IActionSuccess<List<CampusSociety>> success){
        iAction.start("正在加载");
        Map<String, String> params = new HashMap<>();
        params.put(ProtocolKey.SIGNITURE, ProtocolKey.APPSECRET);
        MyRequest<List<CampusSociety>> myRequest = new MyRequest<>(
                Request.Method.POST, mSocietyNewsAddress, params,
                new TypeToken<List<CampusSociety>>() {
                },
                new MyRequest.IRequest<List<CampusSociety>>() {
                    @Override
                    public void fail(String msg) {
                        iAction.fail(msg);
                    }

                    @Override
                    public void success(List<CampusSociety> societies) {
                        success.succes(societies);
                    }

                    @Override
                    public void error(String msg) {
                        iAction.error(msg);
                    }
                }
        );
        RQManager.queue().add(myRequest);
    }

}
